/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __PONY_DS18B20_H__
#define __PONY_DS18B20_H__

/* includes (standard library, system) ---------------------------------------*/
#include <stdint.h>
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/

/* ROM operation */
#define DS18B20_READ_ROM     0x33 /* Read ROM */
#define DS18B20_MATCH_ROM    0x55 /* Match ROM */
#define DS18B20_SKIP_ROM     0xCC /* Skip ROM */
#define DS18B20_ALARM_SEARCH 0xEC /* Search alarm devices on the bus */
#define DS18B20_SEARCH_ROM   0xF0 /* Search ROM */

/* memory operation */
#define DS18B20_READ_SCRATCHPAD  0xBE /* Read the contents of the scratchpad */
#define DS18B20_WRITE_SCRATCHPAD 0x4E /* Write data to scratchpad */
#define DS18B20_COPY_SCRATCHPAD  0x48 /* Copy data from scratchpad to EEPROM */

#define DS18B20_CONVERT_T         0x44 /* Start temperature conversion */
#define DS18B20_READ_POWER_SUPPLY 0xB4 /* Read power supply */
#define DS18B20_RECALL_E2         0xB8 /* Recall data from EEPROM */

#define DS18B20_PRECISION 0x7F   // 1f=9bit; 3f=10bit; 5f=11bit; 7f=12bit;
#define DS18B20_ALARM_TH  0x64   // 100 'C
#define DS18B20_ALARM_TL  0x8a   // -10 'C

/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern int ds18b20_read_temp(uint8_t *minus, uint16_t *temp);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __PONY_DS18B20_H__ */
